﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stone_Jumper
{
    public class Bars
    {
        private List<PointF> _shownBars = new List<PointF>();
        private float _speed;

        public float Speed { get { return _speed; }
            set { _speed = value; }
        }
        public List<PointF> ShownBars
        {
            get { return _shownBars; }
            set { _shownBars = value; }
        }

        private readonly int barDistance = 60;
        private int _barHeight = 20;
        private readonly Queue<MovabledObject> _bars = new Queue<MovabledObject>();
        
        private readonly int _barWidth = 100;
        private readonly int _numberOfBars = 15;
      
        private const float Num = 0f;
        private readonly MySize _formSize;
        private readonly Random _random = new Random();
        public Bars(int barDistance,int barHeight,int barWidth,int numberOfBars, MySize formSize)
        {
            this._formSize = formSize;
            this._barHeight = barHeight;
            this._barWidth = barWidth;
            this.barDistance = barDistance;
            this._numberOfBars = numberOfBars;
        }

        public Bars(MySize formSize)
        {
            this._formSize = formSize;
            _speed = 1;
            InitBars();

        }

        private void InitBars()
        {
            this._bars.Clear();
            for (int i = 0; i < 1000; i++)
            {
                var position = new PointF(this._random.Next(0, _formSize.Width - _barWidth), (float)(this._formSize.Height - (((i + 1) * this.barDistance) + this._random.Next(0, 100))));
                this._bars.Enqueue(new MovabledObject(position));
            }
            for (int j = 0; j < (this._numberOfBars + 1); j++)
            {
                this._shownBars.Add(this._bars.Dequeue().position);
            }
        }
        public void MoveBarsDown()
        {
           
                for (int i = 0; i < (this._numberOfBars + 1); i++)
                {
                    PointF tf2 = this._shownBars[i];
                    PointF tf3 = this._shownBars[i];
                    this._shownBars[i] = new PointF(tf2.X, tf3.Y + this._speed);
                    PointF tf4 = this._shownBars[i];
                    if (tf4.Y > (_formSize.Height + 10))
                    {
                        this._shownBars.RemoveAt(i);
                        PointF position = this._bars.Dequeue().position;
                        this._shownBars.Add(new PointF(position.X, position.Y + Num));
                    }
                    
                }
         
                
            
        }

    }
}
